package com.example.concurrent.demo.aqs;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

/**
 * @author susc
 * @title: CompletableFutureTest
 * @projectName concurrent-demo
 * @description: TODO
 * @date 2021/9/2816:41
 */
public class CompletableFutureTest2 {

    private static CompletableFuture<String> doSomething(String filePath){
        // dosomething
        return CompletableFuture.supplyAsync(
                () -> {
                    System.out.println(filePath);
                    return "sss";
                }

        );
    }

    public static void main(String[] args) {
        // 文件夹位置
        List<String> filePaths = Arrays.asList("1", "2", "3","4");
        // 将他们合并起来
        final CompletableFuture<Void> allFuture = CompletableFuture.allOf(filePaths.stream().map(
                CompletableFutureTest2::doSomething
        ).toArray(CompletableFuture[]::new));
        allFuture.join();
        System.out.println("all do finish!");

    }
}
